﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

//Write a program that reads a number N and calculates the sum of the first N members of the sequence of Fibonacci: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, …
//Each member of the Fibonacci sequence (except the first two) is a sum of the previous two members.


namespace _07FibonacciNMembers
{
    class _07FibonacciNMembers
    {
        static void Main(string[] args)
        {
            Console.Write("The first N numbers of the Fibonacci sequence:\nEnter value for N = ");
            string strN = Console.ReadLine();
            BigInteger valueN = BigInteger.Parse(strN);
            Console.WriteLine("The value of N you entered is " + valueN);
            BigInteger fibFirst = 1;
            BigInteger fibSecond = 2;
            BigInteger fibThird = 3;
            Console.Write("{0}, {1}, {2}, ", fibFirst, fibFirst, fibSecond);
            BigInteger total = 4;
            while (valueN > 3)
            {
                fibThird = fibFirst + fibSecond;
                Console.Write("{0}, ", fibThird);
                fibFirst = fibSecond;
                fibSecond = fibThird;
                total = total + fibThird;
                valueN--;
            }
            Console.WriteLine("\nThe sum of the first {0} members is {1}.", strN, total);
            Console.ReadLine();
        }
    }
}
